package com.basic.business.print.controller;


import java.util.List;
import java.io.IOException;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import com.basic.common.annotation.FileExport;
import com.basic.common.utils.easyExcel.EasyExcelUtils;
import org.springframework.web.bind.annotation.*;
import com.basic.common.annotation.Log;
import com.basic.common.core.controller.BaseController;
import com.basic.common.core.domain.AjaxResult;
import com.basic.common.enums.BusinessType;
import com.basic.business.print.domain.TOrdersPrint;
import com.basic.business.print.service.ITOrdersPrintService;
import com.basic.common.core.page.TableDataInfo;

/**
 * 印刷品管理Controller
 *
 * @author zhaoxy_jn@163.com
 */
@RestController
@RequestMapping("/business/ordersPrint")
public class TOrdersPrintController extends BaseController
{
    @Resource
    private ITOrdersPrintService tOrdersPrintService;

    /**
     * 查询印刷品管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:ordersPrint:list')")
    @GetMapping("/list")
    public TableDataInfo list(TOrdersPrint tOrdersPrint)
    {
        startPage();
        List<TOrdersPrint> list = tOrdersPrintService.getList(tOrdersPrint);
        return getDataTable(list);
    }

    /**
     * 导出印刷品管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:ordersPrint:export')")
    @Log(title = "印刷品管理", businessType = BusinessType.EXPORT)
    @FileExport(fileName = "印刷品管理.xlsx")
    @PostMapping("/export")
    public String export(TOrdersPrint tOrdersPrint) throws IOException
    {
        List<TOrdersPrint> list = tOrdersPrintService.getList(tOrdersPrint);
        return EasyExcelUtils.excelExport(TOrdersPrint.class,"印刷品管理数据", list);
    }

    /**
     * 获取印刷品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:ordersPrint:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tOrdersPrintService.get(id));
    }

    /**
     * 新增印刷品管理
     */
    @PreAuthorize("@ss.hasPermi('business:ordersPrint:add')")
    @Log(title = "印刷品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TOrdersPrint tOrdersPrint)
    {
        return toAjax(tOrdersPrintService.insert(tOrdersPrint));
    }

    /**
     * 修改印刷品管理
     */
    @PreAuthorize("@ss.hasPermi('business:ordersPrint:edit')")
    @Log(title = "印刷品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TOrdersPrint tOrdersPrint)
    {
        return toAjax(tOrdersPrintService.update(tOrdersPrint));
    }

    /**
     * 删除印刷品管理
     */
    @PreAuthorize("@ss.hasPermi('business:ordersPrint:remove')")
    @Log(title = "印刷品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tOrdersPrintService.deleteByIds(ids));
    }

    /**
     * 状态变更
     */
    @PreAuthorize("@ss.hasPermi('business:ordersPrint:changeStatus')")
    @Log(title = "印刷品管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestParam("ids") String[] ids, @RequestParam("status") String status)
    {
        return toAjax(tOrdersPrintService.updateStatusByIds(ids, status));
    }

    /**
     * 刷新缓存
     */
    @PreAuthorize("@ss.hasPermi('business:ordersPrint:refreshCache')")
    @Log(title = "印刷品管理", businessType = BusinessType.CLEAN)
    @DeleteMapping("/refreshCache")
    public AjaxResult refreshCache()
    {
        tOrdersPrintService.resetPrintCache();
        return success();
    }

    /**
     * 检查印刷品编码是否已存在
     */
    @GetMapping("/getDoesIsExist")
    public AjaxResult getDoesIsExist(String printCode,String updateRowId){
        List<TOrdersPrint> list = tOrdersPrintService.getDoesIsExist(printCode,updateRowId);
        return AjaxResult.success(list);
    }
}
